﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.plaf.basic {
    import flash.geom.*;
    import org.aswing.*;
    import org.aswing.geom.*;
    import org.aswing.graphics.*;

    public class BasicGraphicsUtils {

        public static var gradientRatio:Array = [0, 0xFF];
        public static var roundRectBtmFix:Number = 0.5;
        private static var sharedMatrix:Matrix = new Matrix();

        public static function getGradientBrush(_arg1:StyleResult, _arg2:Matrix, _arg3:Boolean=false, _arg4:Array=null):GradientBrush{
            var _local5:ASColor;
            var _local6:ASColor;
            if (_arg3){
                _local5 = _arg1.blight;
                _local6 = _arg1.bdark;
            } else {
                _local5 = _arg1.clight;
                _local6 = _arg1.cdark;
            };
            if (_arg4 == null){
                _arg4 = gradientRatio;
            };
            return (new GradientBrush(GradientBrush.LINEAR, [_local5.getRGB(), _local6.getRGB()], [_local5.getAlpha(), _local6.getAlpha()], _arg4, _arg2));
        }
        public static function drawRoundRect(_arg1:Graphics2D, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Number):void{
            var _local7:Number = ((_arg6 > 5)) ? 0 : roundRectBtmFix;
            _arg1.roundRect(_arg2, _arg3, _arg4, _arg5, _arg6, _arg6, (_arg6 + _local7), (_arg6 + _local7));
        }
        public static function fillGradientRoundRect(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:StyleResult, _arg4:Number=1.5707963267949, _arg5:Boolean=false, _arg6:IntRectangle=null, _arg7:Array=null):void{
            var _local9:Number;
            if (_arg6 == null){
                _arg6 = _arg2;
            };
            sharedMatrix.createGradientBox(_arg6.width, _arg6.height, _arg4, _arg6.x, _arg6.y);
            _arg1.beginFill(getGradientBrush(_arg3, sharedMatrix, _arg5, _arg7));
            var _local8:Number = _arg3.round;
            if (_local8 < roundRectBtmFix){
                _arg1.rectangle(_arg2.x, _arg2.y, _arg2.width, _arg2.height);
            } else {
                _local9 = roundRectBtmFix;
                if (_local8 > 5){
                    _local9 = 0;
                };
                _arg1.roundRect(_arg2.x, _arg2.y, _arg2.width, _arg2.height, _local8, _local8, (_local8 + _local9), (_local8 + _local9));
            };
            _arg1.endFill();
        }
        public static function fillGradientRoundRectBottomRightAngle(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:StyleResult, _arg4:Number=1.5707963267949, _arg5:Boolean=false, _arg6:IntRectangle=null):void{
            var _local8:Number;
            if (_arg6 == null){
                _arg6 = _arg2;
            };
            sharedMatrix.createGradientBox(_arg6.width, _arg6.height, _arg4, _arg6.x, _arg6.y);
            _arg1.beginFill(getGradientBrush(_arg3, sharedMatrix, _arg5));
            var _local7:Number = _arg3.round;
            if (_local7 < roundRectBtmFix){
                _arg1.rectangle(_arg2.x, _arg2.y, _arg2.width, _arg2.height);
            } else {
                _local8 = roundRectBtmFix;
                if (_local7 > 5){
                    _local8 = 0;
                };
                _arg1.roundRect(_arg2.x, _arg2.y, _arg2.width, _arg2.height, _local7, _local7, 0, 0);
            };
            _arg1.endFill();
        }
        public static function drawRoundRectLine(_arg1:Graphics2D, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Number, _arg7:Number):void{
            var _local8:Number;
            if (_arg6 < roundRectBtmFix){
                _arg1.rectangle(_arg2, _arg3, _arg4, _arg5);
                _arg1.rectangle((_arg2 + _arg7), (_arg3 + _arg7), (_arg4 - (_arg7 * 2)), (_arg5 - (_arg7 * 2)));
            } else {
                _local8 = roundRectBtmFix;
                if (_arg6 > 5){
                    _local8 = 0;
                };
                _arg1.roundRect(_arg2, _arg3, _arg4, _arg5, _arg6, _arg6, (_arg6 + _local8), (_arg6 + _local8));
                _arg6 = (_arg6 - (_arg7 / 2));
                _arg1.roundRect((_arg2 + _arg7), (_arg3 + _arg7), (_arg4 - (_arg7 * 2)), (_arg5 - (_arg7 * 2)), _arg6, _arg6, (_arg6 + _local8), (_arg6 + _local8));
            };
        }
        public static function drawGradientRoundRectLine(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:Number, _arg4:StyleResult, _arg5:Number=1.5707963267949, _arg6:Boolean=true, _arg7:IntRectangle=null):void{
            var _local8:Number = _arg2.width;
            var _local9:Number = _arg2.height;
            var _local10:Number = _arg2.x;
            var _local11:Number = _arg2.y;
            var _local12:Number = _arg4.round;
            if (_arg7 == null){
                _arg7 = _arg2;
            };
            sharedMatrix.createGradientBox(_arg7.width, _arg7.height, _arg5, _arg7.x, _arg7.y);
            _arg1.beginFill(getGradientBrush(_arg4, sharedMatrix, _arg6));
            drawRoundRectLine(_arg1, _arg2.x, _arg2.y, _arg2.width, _arg2.height, _local12, _arg3);
            _arg1.endFill();
        }
        public static function getArrowPath(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Boolean=true):Array{
            var _local6:Point = new Point(_arg3, _arg4);
            var _local7:Number = _arg1;
            var _local8:Array = new Array();
            _local8.push(nextPoint(_local6, _arg2, ((_local7 / 2) / 2), _arg5));
            var _local9:Point = nextPoint(_local6, (_arg2 + Math.PI), ((_local7 / 2) / 2));
            _local8.push(nextPoint(_local9, (_arg2 - (Math.PI / 2)), (_local7 / 2), _arg5));
            _local8.push(nextPoint(_local9, (_arg2 + (Math.PI / 2)), (_local7 / 2), _arg5));
            return (_local8);
        }
        private static function nextPoint(_arg1:Point, _arg2:Number, _arg3:Number, _arg4:Boolean=false):Point{
            if (_arg4){
                return (new Point(Math.round((_arg1.x + (Math.cos(_arg2) * _arg3))), Math.round((_arg1.y + (Math.sin(_arg2) * _arg3)))));
            };
            return (new Point((_arg1.x + (Math.cos(_arg2) * _arg3)), (_arg1.y + (Math.sin(_arg2) * _arg3))));
        }
        public static function getDisabledColor(_arg1:Component):ASColor{
            var _local2:ASColor = _arg1.getBackground();
            if (_local2 == null){
                _local2 = ASColor.BLACK;
            };
            return (disabledColor(_local2));
        }
        public static function disabledColor(_arg1:ASColor):ASColor{
            var _local2:ASColor = _arg1;
            var _local3:Number = _local2.getHue();
            var _local4:Number = _local2.getLuminance();
            var _local5:Number = _local2.getSaturation();
            if (_local4 < 0.6){
                _local4 = (_local4 + 0.1);
            } else {
                _local4 = (_local4 - 0.1);
            };
            _local5 = (_local5 - 0.2);
            return (ASColor.getASColorWithHLS(_local3, _local4, _local5, _local2.getAlpha()));
        }
        public static function drawUpperedBezel(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:ASColor, _arg4:ASColor, _arg5:ASColor, _arg6:ASColor):void{
            var _local7:Number = _arg2.x;
            var _local8:Number = _arg2.y;
            var _local9:Number = _arg2.width;
            var _local10:Number = _arg2.height;
            var _local11:SolidBrush = new SolidBrush(_arg4);
            _arg1.fillRectangleRingWithThickness(_local11, _local7, _local8, _local9, _local10, 1);
            _local11.setColor(_arg6);
            _arg1.fillRectangleRingWithThickness(_local11, _local7, _local8, (_local9 - 1), (_local10 - 1), 1);
            _local11.setColor(_arg5);
            _arg1.fillRectangleRingWithThickness(_local11, (_local7 + 1), (_local8 + 1), (_local9 - 2), (_local10 - 2), 1);
            _local11.setColor(_arg3);
            _arg1.fillRectangle(_local11, ((_local7 + _local9) - 2), (_local8 + 1), 1, (_local10 - 2));
            _arg1.fillRectangle(_local11, (_local7 + 1), ((_local8 + _local10) - 2), (_local9 - 2), 1);
        }
        public static function drawLoweredBezel(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:ASColor, _arg4:ASColor, _arg5:ASColor, _arg6:ASColor):void{
            var _local7:Number = _arg2.x;
            var _local8:Number = _arg2.y;
            var _local9:Number = _arg2.width;
            var _local10:Number = _arg2.height;
            var _local11:SolidBrush = new SolidBrush(_arg4);
            _arg1.fillRectangleRingWithThickness(_local11, _local7, _local8, _local9, _local10, 1);
            _local11.setColor(_arg4);
            _arg1.fillRectangleRingWithThickness(_local11, _local7, _local8, (_local9 - 1), (_local10 - 1), 1);
            _local11.setColor(_arg5);
            _arg1.fillRectangleRingWithThickness(_local11, (_local7 + 1), (_local8 + 1), (_local9 - 2), (_local10 - 2), 1);
            _local11.setColor(_arg5);
            _arg1.fillRectangle(_local11, ((_local7 + _local9) - 2), (_local8 + 1), 1, (_local10 - 2));
            _arg1.fillRectangle(_local11, (_local7 + 1), ((_local8 + _local10) - 2), (_local9 - 2), 1);
        }
        public static function drawBezel(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:Boolean, _arg4:ASColor, _arg5:ASColor, _arg6:ASColor, _arg7:ASColor):void{
            if (_arg3){
                drawLoweredBezel(_arg1, _arg2, _arg4, _arg5, _arg6, _arg7);
            } else {
                drawUpperedBezel(_arg1, _arg2, _arg4, _arg5, _arg6, _arg7);
            };
        }
        public static function paintBezel(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:Boolean, _arg4:ASColor, _arg5:ASColor, _arg6:ASColor, _arg7:ASColor):void{
            if (_arg3){
                paintLoweredBevel(_arg1, _arg2, _arg4, _arg5, _arg6, _arg7);
            } else {
                paintRaisedBevel(_arg1, _arg2, _arg4, _arg5, _arg6, _arg7);
            };
        }
        public static function paintRaisedBevel(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:ASColor, _arg4:ASColor, _arg5:ASColor, _arg6:ASColor):void{
            var _local7:Number = (_arg2.height - 1);
            var _local8:Number = (_arg2.width - 1);
            var _local9:Number = (_arg2.x + 0.5);
            var _local10:Number = (_arg2.y + 0.5);
            var _local11:Pen = new Pen(_arg6, 1, false, "normal", "square", "miter");
            _arg1.drawLine(_local11, _local9, _local10, _local9, ((_local10 + _local7) - 2));
            _arg1.drawLine(_local11, (_local9 + 1), _local10, ((_local9 + _local8) - 2), _local10);
            _local11.setColor(_arg5);
            _arg1.drawLine(_local11, (_local9 + 1), (_local10 + 1), (_local9 + 1), ((_local10 + _local7) - 3));
            _arg1.drawLine(_local11, (_local9 + 2), (_local10 + 1), ((_local9 + _local8) - 3), (_local10 + 1));
            _local11.setColor(_arg4);
            _arg1.drawLine(_local11, _local9, ((_local10 + _local7) - 1), ((_local9 + _local8) - 1), ((_local10 + _local7) - 1));
            _arg1.drawLine(_local11, ((_local9 + _local8) - 1), _local10, ((_local9 + _local8) - 1), ((_local10 + _local7) - 2));
            _local11.setColor(_arg3);
            _arg1.drawLine(_local11, (_local9 + 1), ((_local10 + _local7) - 2), ((_local9 + _local8) - 2), ((_local10 + _local7) - 2));
            _arg1.drawLine(_local11, ((_local9 + _local8) - 2), (_local10 + 1), ((_local9 + _local8) - 2), ((_local10 + _local7) - 3));
        }
        public static function paintLoweredBevel(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:ASColor, _arg4:ASColor, _arg5:ASColor, _arg6:ASColor):void{
            var _local7:Number = (_arg2.height - 1);
            var _local8:Number = (_arg2.width - 1);
            var _local9:Number = (_arg2.x + 0.5);
            var _local10:Number = (_arg2.y + 0.5);
            var _local11:Pen = new Pen(_arg3, 1, false, "normal", "square", "miter");
            _arg1.drawLine(_local11, _local9, _local10, _local9, ((_local10 + _local7) - 1));
            _arg1.drawLine(_local11, (_local9 + 1), _local10, ((_local9 + _local8) - 1), _local10);
            _local11.setColor(_arg4);
            _arg1.drawLine(_local11, (_local9 + 1), (_local10 + 1), (_local9 + 1), ((_local10 + _local7) - 2));
            _arg1.drawLine(_local11, (_local9 + 2), (_local10 + 1), ((_local9 + _local8) - 2), (_local10 + 1));
            _local11.setColor(_arg6);
            _arg1.drawLine(_local11, (_local9 + 1), ((_local10 + _local7) - 1), ((_local9 + _local8) - 1), ((_local10 + _local7) - 1));
            _arg1.drawLine(_local11, ((_local9 + _local8) - 1), (_local10 + 1), ((_local9 + _local8) - 1), ((_local10 + _local7) - 2));
            _local11.setColor(_arg5);
            _arg1.drawLine(_local11, (_local9 + 2), ((_local10 + _local7) - 2), ((_local9 + _local8) - 2), ((_local10 + _local7) - 2));
            _arg1.drawLine(_local11, ((_local9 + _local8) - 2), (_local10 + 2), ((_local9 + _local8) - 2), ((_local10 + _local7) - 3));
        }
        public static function paintButtonBackGround(_arg1:AbstractButton, _arg2:Graphics2D, _arg3:IntRectangle):void{
            var _local4:ASColor = ((_arg1.getBackground() == null)) ? ASColor.WHITE : _arg1.getBackground();
            if (_arg1.isOpaque()){
                if (((((_arg1.getModel().isArmed()) || (_arg1.getModel().isSelected()))) || (!(_arg1.isEnabled())))){
                    _arg2.fillRectangle(new SolidBrush(_local4), _arg3.x, _arg3.y, _arg3.width, _arg3.height);
                } else {
                    drawControlBackground(_arg2, _arg3, _local4, (Math.PI / 2));
                };
            };
        }
        public static function drawControlBackground(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:ASColor, _arg4:Number):void{
            _arg1.fillRectangle(new SolidBrush(_arg3), _arg2.x, _arg2.y, _arg2.width, _arg2.height);
            var _local5:Number = _arg2.x;
            var _local6:Number = _arg2.y;
            var _local7:Number = _arg2.width;
            var _local8:Number = _arg2.height;
            var _local9:Array = [0xFFFFFF, 0xFFFFFF];
            var _local10:Array = [0.75, 0];
            var _local11:Array = [0, 100];
            var _local12:Matrix = new Matrix();
            _local12.createGradientBox(_local7, _local8, _arg4, _local5, _local6);
            var _local13:GradientBrush = new GradientBrush(GradientBrush.LINEAR, _local9, _local10, _local11, _local12);
            _arg1.fillRectangle(_local13, _local5, _local6, _local7, _local8);
        }
        public static function fillGradientRect(_arg1:Graphics2D, _arg2:IntRectangle, _arg3:ASColor, _arg4:ASColor, _arg5:Number, _arg6:Array=null):void{
            var _local7:Number = _arg2.x;
            var _local8:Number = _arg2.y;
            var _local9:Number = _arg2.width;
            var _local10:Number = _arg2.height;
            var _local11:Array = [_arg3.getRGB(), _arg4.getRGB()];
            var _local12:Array = [_arg3.getAlpha(), _arg4.getAlpha()];
            if (_arg6 == null){
                _arg6 = [0, 0xFF];
            };
            var _local13:Matrix = new Matrix();
            _local13.createGradientBox(_local9, _local10, _arg5, _local7, _local8);
            var _local14:GradientBrush = new GradientBrush(GradientBrush.LINEAR, _local11, _local12, _arg6, _local13);
            _arg1.fillRectangle(_local14, _local7, _local8, _local9, _local10);
        }

    }
}//package org.aswing.plaf.basic 
